# coding=utf-8
"""
作者：董新强 
创建时间：2020-3-17
描述： theta估计
"""

import numpy
from scipy.optimize import differential_evolution

from catsim import irt


class Evaluator:
    @staticmethod
    def estimate(response_vector, selected_item_params, bounds: tuple = (-3, 3)) -> float:
        _lower_bound = min(bounds)
        _upper_bound = max(bounds)

        # 分差进化算法
        res = differential_evolution(
            irt.negative_log_likelihood,
            bounds=[[_lower_bound, _upper_bound]],
            args=(response_vector, numpy.array(selected_item_params, numpy.float))
        )

        return res.x[0]
